import maya.cmds as cmds;
import maya.mel;
 
originalWidth = 10;
boomWidth = 12.7;# 0 .5 in to mm
fudge = 0.1;
horizontalBoomFudge = 0.1;
verticalBoomFudge = 0.1;#need to leave room for overhang and warping. #no longer needed since we aren't printing overhang
horizontalChange = boomWidth - originalWidth + horizontalBoomFudge;
verticalChange = boomWidth - originalWidth + horizontalBoomFudge;
  
holeDiameter = 3.7084;#6 screw chart width
oldHoleDiameter = 3.0;
newHoleDiameter = holeDiameter + fudge;
ratio = newHoleDiameter / oldHoleDiameter;

wallThickness = 3.5;

servoWidthDifference = 0.65;
zipWidth = 5.0;
zipThickness= 1.0;

def zipVertical(x,y):
    zipBlock = cmds.polyCube(w=zipThickness, h=boomWidth*3.0,d=zipWidth);
    cmds.select(zipBlock[0],borderBlock[0]);
    cmds.align(y='max',alignToLead=True);
    cmds.align(x='min',alignToLead=True);
    cmds.align(z='min',alignToLead=True);
    cmds.select(zipBlock[0]);
    cmds.move(x,0,y,relative=True);
    cmds.select(borderBlock[0],zipBlock[0]);
    return cmds.polyBoolOp(op=2,useThresholds=1);  
  
  
cmds.SelectAll();
cmds.Delete();
    
cmds.file('C:/Users/Santiago/Documents/maya/scripts/boomMount.STL',i=True);
cmds.SelectAll();
boomMount = cmds.ls(sl=True)#work around for the fact twhat non polys don't have curve3[0] format
cmds.select(boomMount[0]);
cmds.scale(0.1,0.1,0.1);
cmds.rotate(-90,0,0);
cmds.select( "transform1.vtx[1]","transform1.vtx[3]","transform1.vtx[5]","transform1.vtx[7]", "transform1.vtx[83]","transform1.vtx[85]","transform1.vtx[87]","transform1.vtx[89]","transform1.vtx[91]","transform1.vtx[95]","transform1.vtx[99]","transform1.vtx[101]","transform1.vtx[117]","transform1.vtx[119]","transform1.vtx[123]","transform1.vtx[125]" ) ;
cmds.move(0,verticalChange,0,relative=True);
cmds.select( "transform1.vtx[0:7]");
cmds.move(-horizontalChange,0,0,relative=True);
cmds.select( "transform1.vtx[8:81]");
cmds.move(-horizontalChange/2.0,verticalChange/2.0,0,relative=True);
maya.mel.eval("scale -r -p -2.15973cm 1.01cm 1.5cm " + str(ratio) + " 1 " +  str(ratio) + ";");#get this value by applying change through editor and seeing log
 
#move servo brace
cmds.select( "transform1.vtx[116:119]","transform1.vtx[122:125]");
cmds.move(servoWidthDifference,0,0,relative=True)

removeBlock = cmds.polyCube(w=boomWidth*2.0, h=boomWidth/2.0 + wallThickness,d=30);

cmds.select(removeBlock[0],"transform1");
cmds.align(y='max',alignToLead=True);
cmds.align(x='min',alignToLead=True);
cmds.align(z='min',alignToLead=True);
cmds.select(removeBlock[0]);
cmds.move(0,0.01,-0.01,relative=True);#need to add a little fudge for boolean logic
cmds.select("transform1",removeBlock[0]);
borderBlock =  cmds.polyBoolOp(op=2,useThresholds=1);

borderBlock =  zipVertical(-zipThickness/2.0,10);
borderBlock =  zipVertical(-zipThickness/2.0+wallThickness*2.0+boomWidth+horizontalBoomFudge,10);

borderBlock =  zipVertical(-zipThickness/2.0,24);
borderBlock =  zipVertical(-zipThickness/2.0+wallThickness*2.0+boomWidth+horizontalBoomFudge,24);

cmds.select(borderBlock[0]);
cmds.rotate(90,0,0,r=True);
